{**
* general document list
*
* @package   OpenEMR
* @link      http://www.open-emr.org
* @author    Brady Miller <brady.g.miller@gmail.com>
* @copyright Copyright (c) 2017 Brady Miller <brady.g.miller@gmail.com>
* @license   https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
*}
<html>
<head>

{headerShow}
<link rel="stylesheet" href="{$GLOBALS.assets_static_relative}/bootstrap-3-3-4/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="{$GLOBALS.css_header}" type="text/css">
<link rel="stylesheet" href="{$GLOBALS.assets_static_relative}/dropzone-4-3-0/dist/dropzone.css">
<link href="{$GLOBALS.assets_static_relative}/jquery-ui-1-12-1/themes/ui-lightness/jquery-ui.min.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="{$GLOBALS.assets_static_relative}/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.min.css">
{literal}
<style type="text/css">
.warn_diagnostic {
    margin: 10 auto 10 auto;
    color: rgb(255, 0, 0);
    font-size: 1.5em;
}
.ui-autocomplete {
    position: absolute;
    top: 0;
    left: 0;
    min-width:200px;
    cursor: default;
}
.ui-menu-item{
     min-width:200px;
}
.fixed-height{
min-width:200px;
padding: 1px;
max-height: 35%;
overflow: auto;
}
</style>
{/literal}
<script type="text/javascript" src="{$GLOBALS.assets_static_relative}/jquery-min-3-1-1/index.js"></script>
<script type="text/javascript" src="{$GLOBALS.assets_static_relative}/jquery-ui-1-12-1/jquery-ui.min.js"></script>
<script type="text/javascript" src="{$GLOBALS.webroot}/library/js/DocumentTreeMenu.js"></script>
<script type="text/javascript" src="{$GLOBALS.assets_static_relative}/dropzone-4-3-0/dist/dropzone.js"></script>
<script type="text/javascript" src="library/dialog.js?v={$GLOBALS.v_js_includes}"></script>
<script type="text/javascript" src="library/textformat.js?v={$GLOBALS.v_js_includes}"></script>
<script type="text/javascript" src="{$GLOBALS.assets_static_relative}/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.full.min.js"></script>

<script type="text/javascript">
    // dropzone javascript asset translation(s)
    Dropzone.prototype.defaultOptions.dictDefaultMessage = "{xl t='Drop files here to upload'}";
</script>

</head>
<!--<body bgcolor="{$STYLE.BGCOLOR2}">-->
<!-- ViSolve - Call expandAll function on loading of the page if global value 'expand_document' is set -->
{if $GLOBALS.expand_document_tree}
  <body class="body_top" onload="javascript:objTreeMenu_1.expandAll();return false;">
{else}
  <body class="body_top">
{/if}

<div id="documents_list">
    <div class="ui-widget"style="float:right;">
        <button id='pid' class="pBtn" type="button" style="float:right;">0</button>
         <input id="selectPatient" type="text" placeholder="{$place_hld|escape:'html'}">
    </div>
<a id="list_collapse" href="#" onclick="javascript:objTreeMenu_1.collapseAll();return false;">&nbsp;({xl t='Collapse all'|escape:'html'})</a>
<div class="title">{xl t='Documents'|escape:'html'}</div>
{$tree_html}
</div>
<div id="documents_actions">
		{if $message}
			<div class='text' style="margin-bottom:-10px; margin-top:-8px"><i>{$message|escape:'html'}</i></div><br>
		{/if}
		{if $messages}
            <div class='text' style="margin-bottom:-10px; margin-top:-8px"><i>{$messages|escape:'html'}</i></div><br>
		{/if}
		{$activity}
</div>
<script type="text/javascript">
var curpid = "{$cur_pid|escape:'html'}";
var newVersion="{$is_new|escape:'html'}";
var demoPid = "{$demo_pid|escape:'html'}";
var inUseMsg = "{$used_msg|escape:'html'}";
{literal}
if(curpid == demoPid && !newVersion){
    $(".ui-widget").hide();
}
else{
    $("#pid").text(curpid);
}
$(function() {
    $( "#selectPatient" ).autocomplete({
    	source: "{/literal}{$GLOBALS.webroot}{literal}/library/ajax/document_helpers.php",
    	focus: function(event, sel) {
            event.preventDefault();
        },
        select: function(event, sel) {
            event.preventDefault();
            if (sel.item.value == '00' && ! sel.item.label.match('{/literal}{xl t="Reset"|escape:"html"}{literal}')){
            	alert(inUseMsg);
            	return false;
            }
            $(this).val(sel.item.label);
            location.href = "{/literal}{$GLOBALS.webroot}{literal}/controller.php?document&list&patient_id="+sel.item.value+"&patient_name=" + sel.item.label;
            $("#pid").text(sel.item.value);
        },
        minLength: 0
    }).autocomplete("widget").addClass("fixed-height");
 });
$(".pBtn").click(function(event) {
    var $input = $("#selectPatient");
        $input.val('*');
        $input.autocomplete('search'," ");
        $input.val('');
});
$("#list_collapse").detach().appendTo("#objTreeMenu_1_node_1 nobr");

// functions to view and pop out documents as needed.
//
$(function() {
    $("img[id^='icon_objTreeMenu_']").tooltip({
        items: $("img[src*='file3.png']"),
        content: '{/literal}{xl t="Double Click on this icon to pop up document in a new viewer."|escape:"html"}{literal}'
    });

    $("img[id^='icon_objTreeMenu_']").on('dblclick', function (e) {
        let popsrc = $(this).next("a").attr('href') || '';
        if (!popsrc.includes('&view&')) return false;
        popsrc = popsrc.replace('&view&', '&retrieve&') + 'as_file=false';
        let poContentModal = function () {
            let wname = '_' + Math.random().toString(36).substr(2, 6);
            let opt = "menubar=no,location=no,resizable=yes,scrollbars=yes,status=no";
            window.open(popsrc, wname, opt);
        };

        let btnText = '{/literal}{xl t="Full Screen"|escape:"html"}{literal}';
        let btnClose = '{/literal}{xl t="Close"|escape:"html"}{literal}';

        dlgopen(popsrc, 'popdoc', 'modal-xl', 700, '', '', {
            buttons: [
                {text: btnText, close: true, style: 'primary btn-xs', click: poContentModal},
                {text: btnClose, close: true, style: 'default btn-xs'}
            ],
            sizeHeight: 'full',
            allowResize: false,
            allowDrag: true,
            dialogId: '',
            type: 'iframe'
        });
        return false;
    });
});

$(document).ready(function(){{/literal}
    {datetimepickerSupport}
{literal}});{/literal}

</script>
</body>
</html>
